package tech.xs.common.framework.domain.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import tech.xs.common.framework.domain.annotations.Dict;
import tech.xs.common.framework.domain.annotations.DictData;
import tech.xs.common.framework.domain.constant.ModuleNames;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据来源类型
 *
 * @author 沈家文
 * @since 2023/5/10 15:52
 */
@Dict(code = "DataSourceType", name = "数据来源", module = ModuleNames.COMMON)
public enum DataSourceTypeEnum implements BaseEnum {

    /**
     * 系统生成
     */
    @DictData(name = "系统生成", order = 10)
    SystemGeneration(1),

    /**
     * 手动添加
     */
    @DictData(name = "手动添加", order = 10)
    Manual(2);

    @EnumValue
    @JsonValue
    private final int value;

    private static final Map<Integer, DataSourceTypeEnum> mappings = new HashMap<>(values().length);

    static {
        for (DataSourceTypeEnum item : values()) {
            mappings.put(item.getValue(), item);
        }
    }

    DataSourceTypeEnum(int value) {
        this.value = value;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static DataSourceTypeEnum create(int value) {
        return mappings.get(value);
    }

    @Override
    public Integer getValue() {
        return value;
    }

}
